package com.ezjie.ielts.core.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;

import com.ezjie.ielts.R;
import com.ezjie.ielts.application.YsApplication;
import com.ezjie.ielts.util.AppManager;
import com.ezjie.ielts.util.AppUtil;
import com.umeng.analytics.MobclickAgent;

/**
 * base类
 * 
 * @author renyangyang
 *
 */
public abstract class BaseFragmentActivity extends FragmentActivity implements OnClickListener {

	protected YsApplication myApplication;

	public static final String PARAM_LAYOUT_RES = "param_layout_res";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		/**
		 * 将当前activity加入到 stack中
		 */
		AppManager.getAppManager().addActivity(this);
		myApplication = (YsApplication) getApplicationContext();

		// 异常捕获
		// UncaughtException.getInstance().init();
		// UncaughtException.getInstance().setContext(this);
	}

	/**
	 * onClick方法的封装，在此方法中处理点击
	 * 
	 * @param view
	 *            被点击的View对象
	 */
	abstract public void onClickEvent(View view);

	@Override
	public void onClick(View v) {
		onClickEvent(v);
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(this);
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		/**
		 * 关闭当前activity
		 */
		AppManager.getAppManager().finishActivity(this);
		AppUtil.dismissWarnDialog();
	}
	
	@Override
	public void startActivity(Intent intent) {
		super.startActivity(intent);
		overridePendingTransition(R.anim.activity_toleftin_anim, R.anim.activity_toleftout_anim);
	}
	
	@Override
	public void startActivityForResult(Intent intent, int requestCode) {
		super.startActivityForResult(intent, requestCode);
		overridePendingTransition(R.anim.activity_toleftin_anim, R.anim.activity_toleftout_anim);
	}
	
	@Override
	public void finish() {
		super.finish();
		overridePendingTransition(R.anim.activity_torightout_anim, R.anim.activity_torightin_anim);
	}

}
